<template>
	<view class="">
		<u-tabs :list="tabList" :is-scroll="false" :current="current" height="100" @change="tabChange"></u-tabs>
		<view class="content">
			<view class="mh-form" v-if="current == 0">
				<view class="mh-form-title">
					<view class="mh-form-title-left">
						<view class="mh-form-title-color"></view>
						<view class="mh-form-title-txt">客户基本信息</view>
					</view>
				</view>
				<view class="mh-form-card">
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-140">
							客户名称：
						</view>
						<view>{{detailInfo.customer.name}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-140">
							联系人：
						</view>
						<view>{{detailInfo.customer.linkman}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-140">
							联系电话：
						</view>
						<view>{{detailInfo.customer.mobile}}</view>
					</view>
					<view class="mh-form-item">
						<view class="mh-form-item-label width-140">
							客户地址：
						</view>
						<view>{{detailInfo.customer.address}}</view>
					</view>
				</view>
				<view class="mh-form-title">
					<view class="mh-form-title-left">
						<view class="mh-form-title-color"></view>
						<view class="mh-form-title-txt">设备基本信息</view>
					</view>
				</view>
				<view class="mh-form-card">
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							设备名称：
						</view>
						<view>{{detailInfo.name}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							设备分类：
						</view>
						<view>{{detailInfo.categoryName}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							项目名称：
						</view>
						<view>{{detailInfo.projectName}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							制造编号(出厂编号)：
						</view>
						<view>{{detailInfo.factoryCode}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							设备编号：
						</view>
						<view>{{detailInfo.code}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							生产厂家：
						</view>
						<view>{{detailInfo.factory}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							规格型号：
						</view>
						<view>{{detailInfo.model}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							使用部门：
						</view>
						<view>{{detailInfo.deptName}}</view>
					</view>
					<view class="mh-form-item border">
						<view class="mh-form-item-label width-271">
							使用部门联系人：
						</view>
						<view>{{detailInfo.deptLinkman}}</view>
					</view>
					<view class="mh-form-item">
						<view class="mh-form-item-label width-271">
							使用部门联系电话：
						</view>
						<view>{{detailInfo.deptMobile}}</view>
					</view>
				</view>
			</view>
			<view v-if="current == 1">
				<view class="content-item">
					<view class="content-item-left">
						<view class="content-item-left-title">
							累计维保次数
						</view>
						<view class="content-item-left-dec">
							{{total}} 次
						</view>
					</view>
					<u-image src="@/static/home/daiweibao.png" width="92rpx" height="95rpx"></u-image>
				</view>
				<u-empty v-if="repairList.length == 0" mode="list" style="margin-top: 300rpx;"></u-empty>
				<view class="history-item" v-for="(item, index) in repairList" :key="index">
					<view class="history-item-index">
						{{index + 1}}
					</view>
					<view class="history-item-left">
						<view class="history-item-time">
							{{item.maintenanceTime}}
						</view>
						<view class="history-item-text">
							<view class="history-item-text-azr">
								维保人：{{item.maintenancePersonStr}}
							</view>
						</view>
					</view>
					<view class="history-item-right" @click="toRepairDetail(item)">
						查看详情
					</view>
				</view>
				<view class="" style="padding: 80rpx 0;">
					<u-button type="primary" @click="toRepair()">新增维保</u-button>
				</view>
			</view>
			<view v-if="current == 2">
				<view class="content-item">
					<view class="content-item-left">
						<view class="content-item-left-title">
							累计维修安装次数
						</view>
						<view class="content-item-left-dec">
							{{total}} 次
						</view>
					</view>
					<u-image src="@/static/home/weixiuanzhuang.png" width="92rpx" height="95rpx"></u-image>
				</view>
				<u-empty v-if="installationList.length == 0" mode="list" style="margin-top: 300rpx;"></u-empty>
				<view class="history-item" v-for="(item, index) in installationList" :key="index">
					<view class="history-item-index">
						{{index + 1}}
					</view>
					<view class="history-item-left">
						<view class="history-item-time">
							{{item.repairInstallTime}}
						</view>
						<view class="history-item-text">
							<view class="history-item-text-azr">
								安装人：{{item.repairInstallPersonStr}}
							</view>
							<view class="history-item-text-azgs">
								安装工时：{{item.workHours}}
							</view>
						</view>
					</view>
					<view class="history-item-right" @click="toInstallationDetail(item)">
						查看详情
					</view>
				</view>
				<view class="" style="padding: 80rpx 0;">
					<u-button type="primary" @click="toInstallation()">新增维修安装</u-button>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				tabList: [{
					name: '基本信息'
				}, {
					name: '维保信息'
				}, {
					name: '维修安装信息'
				}],
				detailInfo: {
					customer: {},
					
				},
				current: 0,
				equipmentId: '',
				queryForm: {
					state: [2, 3],
					pageNum: 1,
					pageSize: 20,
					equipmentId: ''
				},
				total: 0,
				repairList: [],
				installationList: []
			}
		},
		onLoad(option) {
			this.equipmentId = option.equipmentId
			this.queryForm.equipmentId = option.equipmentId
			this.equipmentGetOne()
		},
		onReachBottom() {
			if (this.total > this.queryForm.pageSize * this.queryForm.pageNum && this.current != 0) {
				this.queryForm.pageNum++
				if (this.current == 1) {
					this.maintenanceQuery()
				} else {
					this.repairQuery()
				}
			}
		},
		methods: {
			equipmentGetOne() {
				this.$u.api.equipmentGetOne({
					id: this.equipmentId
				}).then(res => {
					console.log(res);
					this.detailInfo = res
				})
			},
			repairQuery() {
				this.$u.api.repairQuery(this.queryForm).then(res => {
					this.installationList = this.installationList.concat(res.rows)
					this.total = res.recordCount
				})
			},
			maintenanceQuery() {
				this.$u.api.maintenanceQuery(this.queryForm).then(res => {
					this.repairList = this.repairList.concat(res.rows)
					this.total = res.recordCount
				})
			},
			tabChange(e) {
				this.current = e
				if (e != 0) {
					this.queryForm.pageNum = 1
					this.repairList = []
					this.installationList = []
					if (this.current == 1) {
						this.maintenanceQuery()
					} else {
						this.repairQuery()
					}
				}

			},
			toInstallation(item) {
				uni.navigateTo({
					url: '/pages/installation/installation?equipmentId=' + this.equipmentId
				})
			},
			toRepair(item) {
				uni.navigateTo({
					url: '/pages/repair/repair?equipmentId=' + this.equipmentId
				})
			},
			toInstallationDetail(item) {
				uni.navigateTo({
					url: '/pages/installation/detail?id=' + item.id
				})
			},
			toRepairDetail(item) {
				uni.navigateTo({
					url: '/pages/repair/detail?id=' + item.id
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F7FA;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 32rpx 28rpx;


		.content-item {
			background: url('@/static/home/item.png');
			width: 100%;
			height: 200rpx;
			background-size: cover;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 47rpx 56rpx 50rpx 61rpx;
			margin-bottom: 28rpx;

			.content-item-left {
				.content-item-left-title {
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
					line-height: 40rpx;
				}

				.content-item-left-dec {
					font-weight: 600;
					font-size: 48rpx;
					color: #333333;
					line-height: 64rpx;
				}
			}
		}

		.history-item {
			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 58rpx 32rpx 41rpx 46rpx;
			width: 694rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-bottom: 30rpx;


			.history-item-index {
				position: absolute;
				left: 0;
				top: 0;
				line-height: 48rpx;
				background: #3068E7;
				border-radius: 16rpx 0rpx 16rpx 0rpx;
				text-align: center;
				font-weight: 600;
				font-size: 28rpx;
				color: #FFFFFF;
				padding: 0 22rpx;
			}

			.history-item-left {
				.history-item-time {
					font-weight: 600;
					font-size: 36rpx;
					color: #333333;
					line-height: 50rpx;
				}

				.history-item-text {
					font-weight: 400;
					font-size: 26rpx;
					color: #999999;
					line-height: 37rpx;
					display: flex;

					.history-item-text-azr {
						padding-right: 21rpx;
					}

					.history-item-text-azgs {
						padding-left: 21rpx;
						border-left: 1rpx solid #E6E6E6;
					}
				}
			}

			.history-item-right {
				width: 150rpx;
				line-height: 54rpx;
				background: #3068E7;
				border-radius: 30rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				text-align: center;
			}
		}
	}
</style>